
"use strict";
angular.module('app.personal').controller('JoinCompany', function ($scope,$http,personalCenterHttp,userHttpS,$rootScope,jurisHttpS,$cookieStore) {
	//配置分页基本参数
    $scope.paginationConf = {
        currentPage: 1,
        itemsPerPage: 10,
        pagesLength: 5,
        totalItems:20,
        perPageOptions: [10, 20, 30, 40, 50],
        onChange: function(){
        }
    };
    

    //退出公司

	$scope.quit_company = function (company_id) {

	    $scope.quitCompany_postData = {company_id:company_id};
	    $("#posttask").modal("show");
	   

	};

	$scope.quit_company_dialog = function () {

	    userHttpS.postAll('quit_comp', $scope.quitCompany_postData).then(function (data) {

	        if (data > 0) {
	            $("#posttask").modal("hide");
	            UerJoinComp();
	           
	        }

	    })
	};
    //我加入的公司
    var UerJoinComp = function(){
       	// personalCenterHttp.postAll("user_join_comp",$scope.paginationConf).then(function(data){
       	//     console.log(data.content)
       	//     if (data) {
       	//         $scope.paginationConf.totalItems = data['sum'];
       	//         $scope.joincomp = data['content'];
       	//     }
       	//     else {
       	//         $scope.paginationConf.totalItems = 0;
       	//         $scope.joincomp = [];

       	//     }
       	    
      	// })
    };
    $scope.$watch('paginationConf.currentPage + paginationConf.itemsPerPage',UerJoinComp);
    $scope.company = {};
    
	//跳转公司页面
    $scope.tofirst = function(comp_id,comp_name,company_type_id){
		console.log("comp_id is " + comp_id);
		$scope.company.company_id = comp_id;
		$cookieStore.put("comp_id", comp_id);
        //获取动作权限？
		$rootScope.userorcompany = comp_name;

		window.location.href = appConfig.base[0].baseURI + "#/myallprojects/";
    };
	//注册公司
    $scope.comp ={};
    var boon=1;
    $(".this_add").click(function(){
    	if(boon){
    		boon=0;
	    	var content='<tr style="position:relative;">' +
	        '<td><input type="text" placeholder="公司名称不能为空" class="from-control" id="reg_company"/> ' +
				'</td>' +
			'<td class="text-align-left"><select name=""  id="company_type"><option value="3">粮库</option><option value="4">油库</option></select>' +
				'</td>' +
	        '<td class="text-align-center"><input type="text" placeholder="公司简述" class="from-control" id="say_company"/>' +
				'</td>' +
			'<td class="text-align-center">---</td>'+
	        '<td><a class="btn btn-primary sure_add" style="padding:1px 12px; margin-right:5px;">确定</a>' +
	        '<button class="btn btn-primary sure_cancel" style="padding:1px 12px">取消</button></td>' +
	        '</tr>';
	    	$("#add_num").prepend(content);

	    	
	    	$(".sure_add").click(function(){
	    		
	    		$scope.comp.name = $("#reg_company").val();
	    		$scope.comp.des = $("#say_company").val();
	    		$scope.comp.company_type_id = $("#company_type").val();
	    		if($scope.comp.name != ''){
	    		    userHttpS.postAll("register_comp", $scope.comp).then(function (data) {
	    		        if (data) {
                             $.smallBox({
	    		                title: "创建公司成功",
	    		                content: "<i class='fa fa-clock-o'></i> <i>创建公司</i>",
	    		                color: "#659265",
	    		                iconSmall: "fa fa-check fa-2x fadeInRight animated",
	    		                timeout: 4000
	    		            });

	    		            UerJoinComp();
	    		            $(".sure_add").parents('tr').remove();
	    		        }
	    		        else {

	    		            $.smallBox({
	    		                title: "公司未创建成功",
	    		                content: "<i class='fa fa-clock-o'></i> <i>公司未创建成功</i>",
	    		                color: "#a90329",
	    		                iconSmall: "fa fa-check fa-2x fadeInError animated",
	    		                timeout: 4000
	    		            });
	    		        }

	   	    		})
	    		}
	    		boon = 1;
	    	});
	    	$(".sure_cancel").click(function(){
	    		 $scope.comp.name = $("#reg_company").val();
	 		    $(".sure_cancel").parents('tr').remove();
	 		    boon = 1;
	    	});
	    }
    });
});

